//
//  ExhibitTableViewCell.m
//  ArtDog
//
//  Created by dllo on 16/9/8.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ExhibitTableViewCell.h"
#import "BaseCollectionView.h"
#import "ExhibitMainModel.h"
#import "ExhibitArtist.h"
#import "ImageViewCollectionCell.h"
#import "HLMacro.h"
#import "ExhibitWorkDetailsViewController.h"
#import "NSString+Common.h"
#import "UIView+Common.h"

@interface ExhibitTableViewCell ()

@property (weak, nonatomic) IBOutlet UILabel *nameLabel;

@property (weak, nonatomic) IBOutlet UILabel *galleryLabel;

@property (weak, nonatomic) IBOutlet UILabel *cityLabel;

@property (weak, nonatomic) IBOutlet UILabel *viewerLabel;

@property (weak, nonatomic) IBOutlet UILabel *timeLabel;

@property (weak, nonatomic) IBOutlet BaseCollectionView *collectionView;


@end

@implementation ExhibitTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [_collectionView registerNib:[UINib nibWithNibName:@"ImageViewCollectionCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"imageViewCollectionCell"];
    UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout *)_collectionView.collectionViewLayout;
    layout.itemSize = CGSizeMake(SCREEN_WIDTH / 3 - 8, SCREEN_WIDTH / 3 - 8);
    [self collectionViewProcotol];
}

- (void)setExhibitModel:(ExhibitMainModel *)exhibitModel
{
    _exhibitModel = exhibitModel;
    if (exhibitModel.exhibitArtistList != nil || exhibitModel.exhibitArtistList.count != 0) {
        _nameLabel.text = exhibitModel.exhibitArtistList[0].name;
        _galleryLabel.text = exhibitModel.exhibitArtistList[0].galleryName;
        _cityLabel.text = exhibitModel.exhibitArtistList[0].exhibitCity;
        _timeLabel.text = [[[exhibitModel.exhibitArtistList[0].exhibitStartDate substringToIndex:10]stringByAppendingString:@" - "]stringByAppendingString:[[exhibitModel.exhibitArtistList[0].exhibitEndDate substringToIndex:10] substringFromIndex:5]];
    }
    _viewerLabel.text = [NSString stringWithFormat:@"%@", exhibitModel.totalViewNums];
    [_collectionView reloadData];
    
}

- (void)collectionViewProcotol
{
    [_collectionView collectionViewWithNumberOfItems:^(UICollectionView * _Nonnull collectionView, CollectionViewReturnParam * _Nonnull collectionViewParam) {
        collectionViewParam.numberOfItems =  _exhibitModel.exhibitArtistList.count;
    } andCellForItemAtIndexPath:^(UICollectionView * _Nonnull collectionView, NSIndexPath * _Nonnull indexPath, CollectionViewReturnParam * _Nonnull collectionViewParam) {
        ImageViewCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"imageViewCollectionCell" forIndexPath:indexPath];
        cell.urlImage = _exhibitModel.exhibitArtistList[indexPath.item].worksPic;
        collectionViewParam.returnCell = cell;
    } andDidSelectItemAtIndexPath:^(UICollectionView * _Nonnull collectionView, NSIndexPath * _Nonnull indexPath) {
        ExhibitWorkDetailsViewController *detailsVC = [[ExhibitWorkDetailsViewController alloc]init];
        detailsVC.urlString = [NSString getURLStringWith:HOST andPaths:@[@"artgoer/api/v1/user", [NSString getUserDefaultId], @"exhibit/WorkDetailV4", [NSString stringWithFormat:@"%@", [_exhibitModel.exhibitArtistList[indexPath.item]worksId]]] andParams:@{@"token": [NSString getUserDefaultToken], @"userId": [NSString getUserDefaultId], @"workID": [NSString stringWithFormat:@"%@", [_exhibitModel.exhibitArtistList[indexPath.item]worksId]]}];
        UIViewController *vc = [self getVCRecently];
        [vc.navigationController pushViewController:detailsVC animated:YES];
    }];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
